
package com.googlecode.mvndroid;

import com.googlecode.mvndroid.tools.AaptTool;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * @goal resource-src
 * @description Generate the R.java file for project's resources.
 *
 * @author <a href="mailto:1.024e3@gmail.com">Bartosz Duzy</a>
 */

public class Aapt_resource_srcMojo extends AndroidMojo{

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {

        ProcessBuilder processBuilder = new ProcessBuilder();
        AaptTool tool = new AaptTool(this);
        List<String> parameters = new ArrayList<String>();

        getLog().info("Generating R.java / Manifest.java from the resources...");

        parameters.add("package");
        parameters.add("-m");
        parameters.add("-J");
        parameters.add(getSrcDir().getAbsolutePath());
        parameters.add("-M");
        parameters.add(getAndroidManifestFile().getAbsolutePath());
        parameters.add("-S");
        parameters.add(getResDir().getAbsolutePath());
        parameters.add("-I");
        parameters.add(getAndroidJar().getAbsolutePath());

        tool.setParameters(parameters);
        tool.execute(processBuilder);
     
    }

}
